package com.woniu.guoguo.dao;

import com.woniu.guoguo.model.Restaurant;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Richie
 * @since 2020-11-02
 */
public interface RestaurantMapper extends BaseMapper<Restaurant> {

    @Select("SELECT\n" +
            "\trestaurant.restaurant_id, \n" +
            "\trestaurant.shop_name, \n" +
            "\trestaurant.tel, \n" +
            "\trestaurant.address, \n" +
            "\trestaurant.`status`, \n" +
            "\trestaurant.longtitude, \n" +
            "\trestaurant.latitude, \n" +
            "\trestaurant.income\n" +
            "FROM\n" +
            "\trestaurant\n" +
            "WHERE\n" +
            "\trestaurant.`status` = 1\n" +
            "ORDER BY\n" +
            "\tgetDistance(#{myLnt}, #{myLat}, restaurant.longtitude, restaurant.latitude)\n" +
            "LIMIT 0, 5")
    List<Restaurant> getCloseRestaurants(@Param("myLnt") double myLnt, @Param("myLat") double myLat);

    @Update("update restaurant set income=income+#{money} where restaurant_id=#{id}")
    void addMoneyByRestaurantId(@Param("id") Integer restaurantId, @Param("money") Double money);

}
